package com.cn.cs;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import static java.lang.Class.forName;
//更新
public class dome2 {
        public static void main(String[] args)  {
            try {
                forName("com.mysql.jdbc.Driver");
                Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/mysql1","root","root");
                //获取操作数据库的对象
                PreparedStatement pst =con.prepareStatement("update bbb set name=?,sex=?,age=? where id=?");
                //解析占位符
                pst.setString(1,"张三");
                pst.setString(2,"男");
                pst.setInt(3,45);
                pst.setInt(4,4);
                //执行sql获取结果
                int count =pst.executeUpdate();
                System.out.println(count>0?"执行成功":"执行失败");
            } catch (Exception e) {
                e.printStackTrace();
            }

        }
    }
